import 'package:x3_base_core/x3_base_core.dart';

class BaseImageUtils {

  /// 初始化图片的大小
  static String getImageUrlBySize( String imageUrl, BaseImageSizeEnum sizeEnum, BaseImageTypeEnum typeEnum ) {
    if ( typeEnum == BaseImageTypeEnum.X3User || typeEnum == BaseImageTypeEnum.X3Style || typeEnum == BaseImageTypeEnum.X3Depot ) {
      return _getX3ImageUrlBySize( imageUrl, sizeEnum );
    }
    return _getX2ImageUrlBySize( imageUrl, sizeEnum, typeEnum );
  }

 static String _getX3ImageUrlBySize( String imageUrl, BaseImageSizeEnum sizeEnum ) {
    String initImageUrl = BaseUtils.initImageUrl(imageUrl) ?? '';
    switch( sizeEnum ) {
      case BaseImageSizeEnum.small:
        return initImageUrl.replaceFirst('Original', '450x600');
        break;
      case BaseImageSizeEnum.middle:
        return initImageUrl.replaceFirst('Original', '720x1280');
        break;
      case BaseImageSizeEnum.large:
        return initImageUrl.replaceFirst('Original', '1080x1920');
        break;
      case BaseImageSizeEnum.longLarge:
        return initImageUrl.replaceFirst('Original', '1440x2560');
        break;
      case BaseImageSizeEnum.original:
        return initImageUrl;
        break;
    }
    return initImageUrl;
  }

  static String _getX2ImageUrlBySize( String imageUrl, BaseImageSizeEnum sizeEnum, BaseImageTypeEnum typeEnum ) {
    String ftpService = BaseStorageUtil.storageFtpService;
    switch ( typeEnum ) {
      case BaseImageTypeEnum.X3User:
      case BaseImageTypeEnum.X3Style:
      case BaseImageTypeEnum.X3Depot:
      case BaseImageTypeEnum.X3BusinessIcon:
        return BaseUtils.initImageUrl( imageUrl );
      case BaseImageTypeEnum.X2Attachment:
        return ftpService + "/UploadFiles/Attachment/" + imageUrl;
      case BaseImageTypeEnum.X2Brand:
        return ftpService + "/UploadFiles/Brand/" + imageUrl;
      case BaseImageTypeEnum.X2Department:
        return ftpService + "/UploadFiles/Department/" + imageUrl;
      case BaseImageTypeEnum.X2Department1:
        return ftpService + "/UploadFiles/Department1/" + imageUrl;
      case BaseImageTypeEnum.X2Department2:
        return ftpService + "/UploadFiles/Department2/" + imageUrl;
      case BaseImageTypeEnum.X2Style:
        String imageQz = "/UploadFiles/Style/";
        String imageSize = sizeEnum == BaseImageSizeEnum.small ? "48x60" : sizeEnum == BaseImageSizeEnum.middle ? '120x160' : sizeEnum == BaseImageSizeEnum.large ? '450x600' : sizeEnum == BaseImageSizeEnum.longLarge ? '450x600' : 'original';
        return ftpService + imageQz + imageSize + '/' + imageUrl;
        break;
      case BaseImageTypeEnum.X2User:
        return ftpService + "/UploadFiles/User/" + imageUrl;
        break;
      case BaseImageTypeEnum.X2VIP:
        return ftpService + "/UploadFiles/VIP/" + imageUrl;
        break;
      case BaseImageTypeEnum.X2SalesTicketPic:
        return ftpService + "/UploadFiles/SalesTicketPic/" + imageUrl;
      case BaseImageTypeEnum.X2RepairPic:
        return ftpService + "/UploadFiles/RepairPic/" + imageUrl;
    }
    return BaseUtils.initImageUrl( imageUrl );
  }

  /// 初始化占位图
  static String getPlaceholderImage( BaseImageTypeEnum typeEnum ) {
    switch ( typeEnum ) {
      case BaseImageTypeEnum.X3User:
        return BaseAssets.placeholderUserImage;
      case BaseImageTypeEnum.X3Style:
        return BaseAssets.placeholderStyleImage;
      case BaseImageTypeEnum.X3BusinessIcon:
        return BaseAssets.placeholderBusinessIconImage;
      case BaseImageTypeEnum.X3Depot:
        return BaseAssets.placeholderDepotImage;
      case BaseImageTypeEnum.X2Attachment:
        return BaseAssets.placeholderStyleImage;
      case BaseImageTypeEnum.X2Brand:
        return BaseAssets.placeholderDepotImage;
      case BaseImageTypeEnum.X2Department:
        return BaseAssets.placeholderDepotImage;
      case BaseImageTypeEnum.X2Department1:
        return BaseAssets.placeholderDepotImage;
      case BaseImageTypeEnum.X2Department2:
        return BaseAssets.placeholderDepotImage;
      case BaseImageTypeEnum.X2Style:
        return BaseAssets.placeholderStyleImage;
      case BaseImageTypeEnum.X2User:
        return BaseAssets.placeholderUserImage;
      case BaseImageTypeEnum.X2VIP:
        return BaseAssets.placeholderUserImage;
      case BaseImageTypeEnum.X2SalesTicketPic:
        return BaseAssets.placeholderStyleImage;
      case BaseImageTypeEnum.X2RepairPic:
        return BaseAssets.placeholderStyleImage;
    }
    return BaseAssets.placeholderStyleImage;
  }

}
